package com.stt.design.controller;

import com.stt.design.service.DesignTaskService;
import com.stt.design.model.TaskSaveVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/api/task/v2")
public class DesignTaskController {

    @Autowired
    private DesignTaskService designTaskService;

    // 添加任务
    @PostMapping
    public String addTask(@RequestBody TaskSaveVO taskSaveVO) throws InterruptedException {
        for (int i = 0; i < 1000; i++) {
            new Thread(() -> {
                designTaskService.addTask(taskSaveVO);
            }).start();
        }
        TimeUnit.SECONDS.sleep(3);
        System.out.println("任务数量：" + designTaskService.getSize());
        return "添加成功";
    }

    // 获取任务列表
    @GetMapping("/list/{priority}")
    public void listTask(@PathVariable("priority") int priority) {
        designTaskService.getTasks(priority);
    }
}
